<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>
<div class="layui-container">
    <div class="layui-row">
        <button class="layui-btn" onclick="addUser()">添加</button>
        <button class="layui-btn" onclick="exportUser()">导出</button>
    </div>
    <div class="layui-row">
        <table class="layui-table" id="table1"></table>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/layui/layui.all.js"></script>
<script type="text/javascript">
    const $ = layui.$;
    const table = layui.table;
    const layer = layui.layer;
    const baseUrl = "http://127.0.0.1:6677";

    table.render({
        elem: '#table1',
        url: baseUrl + '/demo5/getUsers',
        parseData: function (res) {
            return {
                "code": 0,
                "msg": '',
                "count": res['totalCount'],
                "data": res['list']
            };
        },
        page: true,
        cols: [
            [
                {type: 'checkbox'},
                {type: 'numbers', title: '序号'},
                {field: 'id', title: '主键', hide: true},
                {field: 'name', title: '姓名'},
                {field: 'cardId', title: '身份证号'},
                {field: 'sex', title: '性别'},
                {field: 'age', title: '年龄'},
                {field: 'phone', title: '手机号'},
                {field: 'address', title: '地址'},
            ]
        ]
    });

    function addUser() {
        layer.open({
            type: 2,
            content: 'user',
            title: '录入人员信息',
            area: ['500px', '500px'],
        });
    }

    function exportUser() {
        const checkStatus = table.checkStatus('table1');
        console.log(checkStatus.data)
        if (checkStatus.data.length <= 0) {
            layer.msg("请选择至少一个人");
            return;
        }
        let params = "?";
        for (const obj of checkStatus.data) {
            params += "ids=" + obj['id'] + "&"
        }
        window.location.href = baseUrl + "/demo5/export" + params
    }


</script>
</html>
